package com.situ.cloud.user.handler;

import com.situ.cloud.common.exception.BusinessException;
import com.situ.cloud.common.vo.RS;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ResponseEntity<RS> handler1(BusinessException e) {
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(RS.fail(e.getMsg()));
    }


    @ExceptionHandler(Exception.class)
    public ResponseEntity<RS> handler2(Exception e) {
        e.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(RS.fail("内部服务器出现错误"));
    }

}
